import wx
import os


class UtilityUI(wx.Frame):
    '''
    The GUI
    If on comp, shows the selectable External Devices in a drop down menu.
    If on external drive, shows the drive name in the drop down menu.
    Shows a table of the files located on the drive, with marks indicating
    if there is a file of the same name on the HardDrive. if so, can check the
    BackUp box, which toggles automatic update when program is run.
    Provides the ability to add/remove items from the External drive manually
    '''
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "External Backup Utility", size=(500, 500))
        self.panel = wx.Panel(self, -1)
        
        #Setting up the menu bar
        menuBar = self.MenuBar()
        self.SetMenuBar(menuBar)
        
        ##Instantiates the ListCtrl
        #self.fileList = self.FileList()
        
    
    def MenuBar(self):
        '''
        establishes the Menu Bar and Items
        and bind the items to events.
        '''
        
        menuBar = wx.MenuBar()
        #fileMenu = wx.Menu()
        #menuBar.Append(fileMenu, "&File")
        helpMenu = wx.Menu()
        menuBar.Append(helpMenu, "&Help")
        
        self.__do_layout()
    
    def DriveSizer(self):
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        driveText = wx.StaticText(self.panel, -1, "External Drive: ")
        driveBox = wx.Choice(self.panel, -1, size=(200,-1), choices=["example drive"])
        refreshButton = wx.Button(self.panel, -1, "Refresh Drive")
        sizer.Add(driveText)
        sizer.Add(driveBox)
        sizer.Add(refreshButton, 0, wx.LEFT, 5)
        
        return sizer
    
    def FileList(self):
        list = wx.ListCtrl(self.panel, -1, style=wx.LC_REPORT)
        list.InsertColumn(0, "HD")
        list.InsertColumn(1, "BU")
        list.InsertColumn(2, "Files on external drive")
        
        list.SetColumnWidth(0, wx.LIST_AUTOSIZE_USEHEADER)
        list.SetColumnWidth(1, wx.LIST_AUTOSIZE_USEHEADER)
        list.SetColumnWidth(2, wx.LIST_AUTOSIZE_USEHEADER)
        
        return list
    
    def Buttons(self):
        Save = wx.Button(self.panel, -1, "Save")
        self.Bind(wx.EVT_BUTTON, self.OnSave, Save)
        Cancel = wx.Button(self.panel, -1, "Cancel")
        self.Bind(wx.EVT_BUTTON, self.OnCancel, Cancel)
        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(Save)
        sizer.Add((20,20), 1)
        sizer.Add(Cancel)
        
        return sizer
        
    def __do_layout(self):
        '''
        provides the layout for the GUI
        '''
        mainSizer = wx.BoxSizer(wx.VERTICAL)
        driveSizer = self.DriveSizer()
        self.fileList = self.FileList()
        buttonSizer = self.Buttons()
        
        mainSizer.Add(driveSizer, 0, wx.ALL|wx.CENTER, 5)
        mainSizer.Add(self.fileList, 1, wx.EXPAND|wx.ALL, 5)
        mainSizer.Add(buttonSizer, 0, wx.ALL|wx.ALIGN_RIGHT, 5)
        self.panel.SetAutoLayout(True)
        self.panel.SetSizer(mainSizer)
        self.panel.Layout()
    
    def OnSave(self, evt):
        pass
    
    def OnCancel(self, evt):
        self.Close()

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = UtilityUI()
    frame.Show(True)
    app.MainLoop()